// 工具类小方法
// 倒计时
export const Countdown = function (endtime) {
    function addZero(i){
        return i<10?"0"+i:i+""
        
    }
    let nowTime = new Date();//现在时间
    let endtimes = new Date(endtime)//倒计时结束的时间
    let diff = parseInt((endtimes - nowTime)/1000) //秒差
    let second = parseInt(diff%60)//秒
    let min = parseInt((diff/60)%60)//分钟
    let hour = parseInt((diff/60/60)%24)//小时
    let day = parseInt((diff/60/60/24))
    
    hour = addZero(hour)
    min = addZero(min)
    second = addZero(second)
    
    return{
        day,
        hour,
        min,
        second
    }
}
/**
 * 动画垂直滚动到页面指定位置
 * @param { Number } currentY 当前位置
 * @param { Number } targetY 目标位置
 */
export const scrollAnimation=function(currentY, targetY) {
    // 获取当前位置方法
    // const currentY = document.documentElement.scrollTop || document.body.scrollTop
  
    // 计算需要移动的距离
    let needScrollTop = targetY - currentY
    let _currentY = currentY
    setTimeout(() => {
      // 一次调用滑动帧数，每次调用会不一样
      const dist = Math.ceil(needScrollTop / 10)
      _currentY += dist
      window.scrollTo(_currentY, currentY)
      // 如果移动幅度小于十个像素，直接移动，否则递归调用，实现动画效果
      if (needScrollTop > 10 || needScrollTop < -10) {
        scrollAnimation(_currentY, targetY)
      } else {
        window.scrollTo(_currentY, targetY)
      }
    }, 1)
  }
 